<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>管理员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../assets/js/jquery-1.8.3.min.js"></script>
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script src="../js/admin-list.js"></script>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                        <div class="layui-inline layui-show-xs-block">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="username"  placeholder="请输入管理员姓名" autocomplete="off" id="lookup" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" id="sousou"  lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </div>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn" onclick="xadmin.open('添加用户','./admin-add.html',1000,600)"><i class="layui-icon"></i>添加</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-hide" id="test" lay-filter="test"></table>

                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script id="barDemo" type="text/html">
    <a title="编辑"  lay-event="xg">
        <i class="layui-icon">&#xe642;</i>
    </a>
    <a title="删除" lay-event="sc">
        <i class="layui-icon">&#xe640;</i>
    </a>
</script>
<script type="text/html" id="astate">
    {{# if(d.astate === 0){ }}
    <span class="layui-btn layui-btn-normal layui-btn-mini">正常</span>
    {{# } else { }}
    <span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled">禁用</span>
    {{# } }}
</script>
<script>
    layui.use(['table','jquery','layer'], function(){
        var table = layui.table;
        var $obj=layui.jquery;
        var layer=layui.layer;
        //监听工具条
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if(layEvent === 'xz'){ //查看
                layer.open({
                    type: 2,
                    title:'新增图书',
                    content: ['Insertaction.html','no'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    area: ['1300px', '700px'],
                    resize:false,
                    move: false,
                    end:function(){
                        location.reload();//弹出层结束后，刷新主页面
                    }
                });
            }else if(layEvent === 'xg'){
                sessionStorage.setItem("aid",data.aid);
                sessionStorage.setItem("aname",data.aname);
                sessionStorage.setItem("asex",data.asex);
                sessionStorage.setItem("aage",data.aage);
                sessionStorage.setItem("aphone",data.aphone);
                sessionStorage.setItem("astate",data.astate);
                layer.open({
                    type: 2,
                    title:'修改管理员信息',
                    content: ['admin-edit.html','no'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    area: ['1000px', '600px'],
                    resize:false,
                    move: false,
                    end:function(){
                        location.reload();//弹出层结束后，刷新主页面
                    }
                });
            }else if(layEvent === 'sc'){
                if (confirm("确定要删除吗?")){
                $.ajax({
                    type:'POST',
                    url: "http://localhost:8080/api/del",
                    data: {"id": data.aid},
                    headers: {
                        token: localStorage.getItem("token")
                    },
                    datatype: "json",
                    success: function (data) {
                        if (data.data>0){
                            layer.msg('管理员信息删除成功!',{
                                icon:1
                                ,time:800
                            },function (){
                                location.reload();//刷新界面
                            });

                        }
                    }
                })
                }
            }
        });
    });
</script>

</html>